package mushystuff.dtb.ws.endpoint;

import mushystuff.dtb.core.model.Product;
import mushystuff.dtb.core.service.ProductService;
import mushystuff.dtb.ws.to.ProductTransferObject;

public class ProductServiceEndpoint {

    private ProductService productService;
    
    public ProductServiceEndpoint(ProductService productService) {
        this.productService = productService;
    }

    public void createProduct(String name) {
        Product product = new Product();
        product.setName(name);
        productService.createUpdateProduct(product);
    }
    
    public void modifyProduct(long id, String name, boolean active) {
        Product product = productService.getProduct(id);
        product.setName(name);
        product.setActive(active);
        productService.createUpdateProduct(product);
    }
    
    public ProductTransferObject[] getAllProducts() {
        return ProductTransferObject.toArray(productService.getAllProducts());
    }
    
    public ProductTransferObject[] getAllActiveProducts() {
    	return ProductTransferObject.toArray(productService.getAllActiveProducts());
    }
    
}
